<?php
namespace app\common\model;

use Medoo\Medoo;

/**
 * 数据库模型
 *
 * Class Db
 * @package app\common\model
 */
class Db
{
    protected static $_instance;

    public function __construct()
    {
    }

    /**
     * 实例
     *
     * @return Medoo
     */
    public static function instance()
    {
        if (!(self::$_instance instanceof Db)) {
            self::$_instance= new Medoo(
                [
                    // required
                    'database_type' => Config::get('database_type', 'db'),
                    'database_name' => Config::get('database_name', 'db'),
                    'server' => Config::get('server', 'db'),
                    'username' => Config::get('username', 'db'),
                    'password' => Config::get('password', 'db'),

                    // [optional]
                    'charset' => Config::get('charset', 'db'),
                    'prefix' => Config::get('prefix', 'db'),
                    'port' => Config::get('port', 'db'),
                ]
            );
        }

        return self::$_instance;
    }

    private function __clone()
    {
    }

}